package com.hmkj.core.service.investor.impl;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.core.mapper.investor.InvestorMapper;
import com.hmkj.core.mapper.user.UserMapper;
import com.hmkj.core.po.investor.Investor;
import com.hmkj.core.po.user.User;
import com.hmkj.core.service.investor.InvestorService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 投资人表业务相关Service接口实现<br>
 *
 * @ClassName: InvestorServiceImpl
 * @author eproo
 * @date   2017-11-07 09:04:34
 */
@Service
@Scope("prototype")
@Transactional(rollbackFor = Exception.class)
public class InvestorServiceImpl implements InvestorService {

	@Resource
    private InvestorMapper investorMapper;
    @Resource
    private UserMapper userMapper;

    @Override
    public GenericMapper<Investor,Integer> _getMapper() {
        return investorMapper;
    }

    @Override
    public void add(Investor investor) {
        //更新usertype
        userMapper.updateByPrimaryKeySelective(new User(u->{
            u.setId(investor.getId());
            u.setType(User.TYPE.T2.code);
        }));
        //保存投资人
        Investor iv = new Investor();
        iv.setUserId(investor.getUserId());
        iv.setAccountNo(investor.getAccountNo());
        iv.setAccountPwd(investor.getAccountPwd());
        investorMapper.insert(iv);
    }
}
